package com.bilibili.api;

import com.bilibili.domain.JsonResponse;
import com.bilibili.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * projectName:com.bilibili.api
 *
 * @author 飞
 * @create by 2024/6/1519:33
 * description:
 */
@CrossOrigin
@RestController
@Api(tags = "文件上传接口")
public class FileController {
    @Resource
    private FileService fileService;

    @PostMapping("/md5files")
    @ApiOperation("对文件进行md5加密")
    public JsonResponse<String> getFileMd5(MultipartFile file) throws Exception {
        String fileMD5 = fileService.getFileMd5(file);
        return new JsonResponse<>(fileMD5);
    }

    @PutMapping("/file-slices")
    @ApiOperation("上传文件切片")
    public JsonResponse<String> uploadFileBySlices(MultipartFile slice,
                                                   String fileMD5,
                                                   Integer sliceNo,
                                                   Integer totalSliceNo) throws Exception {
        String filePath = fileService.uploadFileBySlices(slice, fileMD5, sliceNo, totalSliceNo);
        return new JsonResponse<>(filePath);
    }
}
